package com.misboot.document;

import cn.xuyanwu.spring.file.storage.EnableFileStorage;
import com.misboot.document.filter.JwtFilter;
import com.google.common.collect.Lists;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import tk.mybatis.spring.annotation.MapperScan;
import java.util.List;

/**
 * misboot-document模块启动类
 *
 * @Author 湖南佐佑时代科技有限公司
 * @Version 5.4.21
 * @Email service@zuoyo.com
 * @Date 2022-06-13 09:39:40
 */
@SpringBootApplication
@ComponentScan(basePackages = {"cn.ewsd.**.*", "com.misboot.**.*"})
@EnableDiscoveryClient
@EnableFeignClients
@EnableFileStorage
@MapperScan("com.misboot.document.mapper")
public class MISBootDocumentApplication {

    public static void main(String[] args) {
        System.setProperty("nacos.logging.default.config.enabled","false");
        SpringApplication.run(MISBootDocumentApplication.class, args);
    }

    /**
     * 注册JWT拦截器，可以在配置类中，也可以直接在SpringBoot的入口类中
     */
    @Bean
    public FilterRegistrationBean jwtFilter() {
        final FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(new JwtFilter());
        //添加需要拦截的url
        List<String> urlPatterns = Lists.newArrayList();
        urlPatterns.add("*");
        registrationBean.addUrlPatterns(urlPatterns.toArray(new String[urlPatterns.size()]));
        return registrationBean;
    }
}
